package opensocial4gwt;

import com.google.gwt.core.client.JavaScriptObject;

public final class MediaItem extends JavaScriptObject {
	private static enum Field {
		MIME_TYPE, TYPE, URL;

		public String value() {
			return value(name());
		}

		private native static String value(String name) /*-{
			return $wnd.opensocial.MediaItem.Field[name];
		}-*/;
	}

	public static enum Type {
		AUDIO, IMAGE, VIDEO;

		public String value() {
			return value(name());
		}

		private native static String value(String name) /*-{
			return $wnd.opensocial.MediaItem.Type[name];
		}-*/;
	}

	protected MediaItem() {
	}

	public String getMimeType() {
		return getField(Field.MIME_TYPE.value());
	}

	public void setMimeType(String mimeType) {
		setField(Field.MIME_TYPE.value(), mimeType);
	}

	public Type getType() {
		String t = getField(Field.TYPE.value());
		if (t == null)
			return null;
		else
			return Type.valueOf(t);
	}

	public void setType(Type type) {
		if (type == null)
			setField(Field.TYPE.value(), null);
		else
			setField(Field.TYPE.value(), type.value());
	}

	public String getURL() {
		return getField(Field.URL.value());
	}

	public void setURL(String url) {
		setField(Field.URL.value(), url);
	}

	private native String getField(String field) /*-{
		return this.getField(field);
	}-*/;

	private native void setField(String field, String value) /*-{
		return this.setField(field, value);
	}-*/;
}
